/*************************************************************************
 *                                                                       *
 * This file is part of the FreeMAPs distribution.  For full copyright   *
 * information, see COPYRIGHT and COPYING.LESSER.                        *
 *                                                                       *
 * Author:           sqbang                                              *
 * Email:            sqbang@ustc.edu                                     *
 * Date:             2013.11.19                                          *
 *                                                                       *
 *************************************************************************/

//declaration header
#include "COMMON/mesh/NodeGroup.h"

//FreeMAPs headers
#include "COMMON/tbox/LogMessage.h"

namespace FreeMAPs
{

NodeGroup::NodeGroup()
{}



NodeGroup::NodeGroup(
    const std::string& group_name):
    d_group_name (group_name)
{}



NodeGroup::~NodeGroup()
{
    this->clear();
}


void
NodeGroup::clear()
{
    d_nodes.clear();
}



void
NodeGroup::renumber_nodes(
    const std::map<int, int>& node_id_map)
{
    std::set<int> old_nodes (d_nodes);
    d_nodes.clear();
    for (std::set<int>::const_iterator pos = old_nodes.begin();
            pos != old_nodes.end(); ++pos)
    {
        std::map<int, int>::const_iterator find = node_id_map.find (*pos);
        FREEMAPS_ASSERT (find != node_id_map.end());
        d_nodes.insert (find->second);
    }
}



std::ostream&
operator << (
    std::ostream& os,
    const NodeGroup& rhs)
{
    FREEMAPS_ASSERT (!rhs.d_group_name.empty());
    os << rhs.d_group_name << "\n{\n";
    for (std::set<int>::const_iterator pos = rhs.d_nodes.begin();
            pos != rhs.d_nodes.end(); ++pos)
    {
        os << LogMessage::get_prefix (ONE_TAB) << *pos << '\n';
    }

    os << "}";

    return os;
}

}
